<?php 
	$coord_client= ($_GET['coord_client']);
	echo $coord_client ;
 ?>
<html>
<head>
<meta charset="UTF-8" />
	<title>Onglets</title>
	
<title>Distance finder</title>
<meta type="description" content="Find the distance between two places on the map and the shortest route."/>
<div class="emarge" id="accueil_content" style="background-image: url(images/accueil.gif); background-position:bottom center; background-repeat:no-repeat; height:97%">

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=true"></script>
<script type="text/javascript" src="js/script.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />



</head>

<body>		

<?php
// connect to the database
include "connect.php";

	// adding a new location to the db
	if (isset($_POST['name']))
	{
		$name = $_POST['name'];
		
		$photo = $_FILES['photo']['name'];
		
		
		
		$lat = $_POST['lat'];
		$long = $_POST['long'];
		$address = $_POST['address'];

		// generate id
		$id = 1;
		$result = mysql_query("select max(id) from locations");
		if (mysql_num_rows($result) != 0)
		{
			$row = mysql_fetch_array($result);
			$id = $row['max(id)']+1;
		}
		
		// photo name
		$photo_name = "./photos/".$id."_photo.jpg";
		
		// sql query to add location
		$result = mysql_query("insert into locations (`name`, `latitude`, `longitude`, `address`, `photo`) 
									values ('$name', '$lat', '$long', '$address', '$photo_name')");
									
		//upload photo
		move_uploaded_file($_FILES['photo']['tmp_name'],"./photos/".$id."_photo.jpg");
		
		//resize photo
		$simg = imagecreatefromjpeg("./photos/".$id."_photo.jpg");   
		$currwidth = imagesx($simg);   
		$currheight = imagesy($simg);   
		
		// new width = 200px
		$twidth = "200";
		$zoom = $twidth / $currwidth;   
		$newwidth = $twidth;   
		$newheight = $currheight * $zoom;   

		$dimg = imagecreatetruecolor($newwidth, $newheight);    
		imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);   
		imagejpeg($dimg, "./photos/".$id."_photo.jpg"); 

		// update photo name
		$result = mysql_query("update locations set `photo`='".$id."_photo.jpg' where id=".$id);
	}
	?>




 	
<ul id="onglets">
	<li class="actif">Géolocalisation</li>
	<li>Plus proche livreur</li>
	<li>Enregistrer coordonnees client</li>
</ul>

<div id="contenu">
	<div class="item">
			<h2>Localiser (Fournissuer + Livreur) % client</h2>
		<table width="370" border=1 cellspacing=1 cellpadding=12>
		  <tr>
			
		  </tr>
		  <tr>
			  <th width="180" height="25" align="center" bgcolor="#99CCFF" scope="row"><pre>Adresse de client:</pre></th>
			<th bgcolor="#6699CC" scope="row"><p><input name="address3" type="text"  size="30" maxlength="50"/></p></th>
		  </tr> 
		  <tr>
			<th width="180" height="45" align="center" bgcolor="#99CCFF" scope="row"><pre>Adresse de livreur:</pre></th>
			<th bgcolor="#6699CC" scope="row"><p><input type="text" name="address1" id="address1" size="30"/></p></th>
		  </tr>
		  <tr>
			<th width="180" height="45" align="center" bgcolor="#99CCFF" scope="row"><pre>Adresse de fournisseur:</pre></th>
			<th bgcolor="#6699CC" scope="row"><p><input name="address2" type="text" id="address2" size="30" /></p></th>
		  </tr>
		  <tr>
			<th height="45" align="center" bgcolor="#99CCFF" scope="row"><pre>Moyen de transport:</pre></th>
			<th bgcolor="#6699CC" scope="row"><select id="travelMode" name="travelMode" >
								<option value="driving">Voiture</option> 
								<!--<option value="walking">Avion</option> -->
								<!--<option value="bicycling">bicyclette</option>  -->
			  </select></th>
		  </tr>
		  <tr>
			<th colspan="2" scope="row">
			  <p>
				<input type="button" value="Localiser" onClick="initialize();"/>
			  </p></th>
		  </tr>
  </table>
</div>

<div class="item" >
	<h2>Plus proche livreur</h2>
    <table width="450" border=2 cellspacing=6 cellpadding=10>
		<?php 
		  for ($i=0 ; $i<4 ; $i++)
		  { 
		  ?>  
	  <tr bgcolor="#99CCFF" >
			<th colspan="2" scope="row" align="justify" id="distance_direct_<?php echo $i; ?>" style="width:100%; height:5%; font-family: 'Times New Roman', Times, serif; font-size: 12px; text-align: center;">	
			<pre>&nbsp;</pre></th>
		  </tr>
		 <?php 
		  } 
		  ?>
		 
		<?php 
		  for ($i=1 ; $i<2 ; $i++)
		  { 
		  ?>   
		  <tr bgcolor="#99FFFF" >
			<th colspan="2" align="justify" id="distance_road_<?php echo $i; ?>" style="width:100%; height:5%; font-family: 'Times New Roman', Times, serif; font-size: 12px; text-align: center;" scope="row">	
			<pre>&nbsp;</pre></th>
		  </tr>
		  <?php 
		  } 
		  ?>
           <tr bgcolor="#99CCFF" >
			<th colspan="2" scope="row" align="justify" id="distance_short" style="width:100%; height:5%; font-family: 'Times New Roman', Times, serif; font-size: 12px; text-align: center;">	
			<pre>&nbsp;</pre></th>
		  </tr>
    </table>
  
</div>

<div class="item">
			<h2>Enregistrer coordonnées client</h2>
		<form action="distance-livreurs-fournisseurs.php" method="post" name="add" id="add" enctype="multipart/form-data" onSubmit="return check();">

				<table align="left" border=1 cellspacing=1 cellpadding=12>
					<tr>
						<td width="158" align="center" bgcolor="#99CCFF">
					  <pre><strong>Nom:</strong></pre></td>
						
						<th colspan="2" bgcolor="#6699CC"><input name="name" id="name" type="text" size="30"/></th>
					</tr>
			      <tr>
				      <td rowspan="2" align="center" bgcolor="#99CCFF">
			        <pre><strong>Coordonées:</strong></pre></td>
				      
				      <th width="45" bgcolor="#6699CC"><pre>lat: </pre></th>
				      <th width="155" bgcolor="#6699CC"><input name="lat" id="lat" type="text" size="20" readonly/></th>
			      </tr>
			      <tr>
					<th bgcolor="#6699CC"><pre>long:</pre></th>
					  <th bgcolor="#6699CC"><input name="long" id="long" type="text" size="20" readonly/></th>
				  </tr>
					<tr>
						<td align="center" bgcolor="#99CCFF">
					  <pre><strong>Adresse:</strong></pre></td>
						
						<th colspan="2" bgcolor="#6699CC"><input name="address" id="address" type="text" size="30" readonly/></th>
					</tr>
					
					<tr>
						<td align="center" bgcolor="#99CCFF"><pre><strong>Photo:</strong></pre></td>
						
						<th colspan="2" bgcolor="#6699CC"><input id="photo" name="photo" type="file"/></th>
					</tr>
					
					
					<tr bgcolor="#99CCFF">
						<td colspan="4" align="center"><input type="submit" value="Ajouter"/></td>
					</tr>
				</table>

</form>
</div>
		
</div> 
	
	
<center><div id="map_canvas" style="width: 60%;height: 88%; display: inline-block;"></div></center> 
	
</div>	
</body>
</html>